//
//  DynamicViewModel.m
//  fitness-iOS
//
//  Created by 卢仕彤 on 2018/1/10.
//  Copyright © 2018年 卢仕彤. All rights reserved.
//

#import "DynamicViewModel.h"
#import "FFGlobalHeader.h"
#import "UIImageView+RoundImage.h"
#import "UIImageView+WebCache.h"


@implementation DynamicViewModel

@end

@interface SDCycleScrollCell ()
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@end

@implementation SDCycleScrollCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier imageArray:(NSArray *)imageArray; {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageInfoArray = imageArray;
        [self initView];
    }
    return self;
}

- (void)initView {
    [self.contentView addSubview:self.cycleScrollView];
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left);
        make.right.equalTo(self.contentView.right);
        make.top.equalTo(self.contentView.top);
        make.bottom.equalTo(self.contentView.bottom);
    }];
}

#pragma -mark ------------------lazy init----------------------

- (SDCycleScrollView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imagesGroup:self.imageInfoArray];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    }
    return _cycleScrollView;
}

@end

@interface DynamicStoryCell ()
@property (nonatomic, strong) DynamicCellContentView *cellContentView;
@end

@implementation DynamicStoryCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.height.equalTo(@25);
    }];
    
    [self.cellContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(_titleLabel.mas_bottom).offset(9.5);
        make.bottom.equalTo(self.contentView);
    }];
}
#pragma -mark ------------------lazy inti----------------------

- (UILabel*)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:18] textColor:[UIColor colorWithHexString:@"#2D3037"]];
        _titleLabel.textAlignment = NSTextAlignmentJustified;
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (DynamicCellContentView *)cellContentView {
    if (_cellContentView == nil) {
        _cellContentView = [[DynamicCellContentView alloc]init];
        _cellContentView.delegate = self;
        _cellContentView.mainName = KStory;
        _cellContentView.modelArray = @[@"21",@"23",@"123"];
        [self.contentView addSubview:_cellContentView];
    }
    return _cellContentView;
}
-(void)seeAllContent
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(ff_showSeeDetailCollectContent:)]) {
        
    }
}

#pragma mark--RecommendCellContentViewDelegate
-(void)ff_showDidSelectItem:(DynamicDetailModel *)model mainName:(NSString *)mainName
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(ff_showDidSelectCellItem: mainName:)]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.delegate ff_showDidSelectCellItem:model mainName:mainName];
        });
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Configure the view for the selected state
}

@end

@interface DynamicPlanCell ()<DynamicCellContentViewDelegae>
@property (nonatomic, strong) DynamicCellContentView *cellContentView;
@end

@implementation DynamicPlanCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(20);
        make.top.equalTo(self.contentView.mas_top).offset(10);
        make.height.equalTo(@25);
    }];
    
    [self.cellContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(_titleLabel.mas_bottom).offset(9.5);
        make.bottom.equalTo(self.contentView);
    }];
}

-(void)seeAllContent
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(ff_showSeeDetailCollectContent:)]) {
        
    }
}

#pragma mark--RecommendCellContentViewDelegate
-(void)ff_showDidSelectItem:(DynamicDetailModel *)model mainName:(NSString *)mainName
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(ff_showDidSelectCellItem: mainName:)]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.delegate ff_showDidSelectCellItem:model mainName:mainName];
        });
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Configure the view for the selected state
}



#pragma -mark ------------------lazy inti----------------------

- (UILabel*)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:18] textColor:[UIColor colorWithHexString:@"#2D3037"]];
        _titleLabel.textAlignment = NSTextAlignmentJustified;
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (DynamicCellContentView *)cellContentView {
    if (_cellContentView == nil) {
        _cellContentView = [[DynamicCellContentView alloc]init];
        _cellContentView.delegate = self;
        _cellContentView.mainName = KLearb;
        _cellContentView.modelArray = @[@"21",@"23",@"23"];
        [self.contentView addSubview:_cellContentView];
    }
    return _cellContentView;
}
@end


@interface DynamicCollectionViewCell ()
@property(nonatomic,strong)UIImageView *backImageView;//展示图
@property(nonatomic,strong)UILabel     *pageNameLabel;//文章标题
@property(nonatomic,strong)UILabel *videoLabel;
@end

@implementation DynamicCollectionViewCell
    
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self configUI];
    }
    return self;
}
#pragma mark--UI布局部分
-(void)configUI {
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.equalTo(@100);
    }];
    
    [self.videoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImageView.left).offset(5);
        make.bottom.equalTo(self.backImageView.bottom).offset(-5);
        make.right.equalTo(self.backImageView.right).offset(-5);
    }];
    
    //文章标题
    [self.pageNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_backImageView);
        make.top.equalTo(_backImageView.bottom).offset(5);
    }];
    
}
#pragma mark--更新cell参数
- (void)setModel:(DynamicDetailModel *)model {
    _model = model;
}
#pragma mark ------------------------------- Setter／Getter -------------------------------

#pragma mark--展示view懒加载部分
//展示图
-(UIImageView*)backImageView;
{
    if (_backImageView == nil) {
        _backImageView = [[UIImageView alloc]init];
        _backImageView.layer.cornerRadius = 4.0f;
        _backImageView.userInteractionEnabled = NO;
        _backImageView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:_backImageView];
    }
    return _backImageView;
}

//文章标题
-(UILabel*)pageNameLabel
{
    if (_pageNameLabel == nil) {
        _pageNameLabel = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:16] textColor:[UIColor colorWithHexString:@"#333333"]];
        _pageNameLabel.text = @"健美老师,手把手教你";
        _videoLabel.numberOfLines = 0;
        [self.contentView addSubview:_pageNameLabel];
    }
    return _pageNameLabel;
}

- (UILabel *)videoLabel {
    if (_videoLabel == nil) {
        _videoLabel = [UILabel labelWithSystemFontSize:20 textColorHexString:@"#FFFFFF"];
        _videoLabel.font = [UIFont boldSystemFontOfSize:20];
        _videoLabel.numberOfLines = 0;
        _videoLabel.text = @"杠铃划船教程";
        [self.contentView addSubview:_videoLabel];
    }
    return _videoLabel;
}
@end

@interface DynamicStoryViewCell ()
@property (nonatomic, strong )UIImageView *backImageView;//展示图
@property (nonatomic, strong )UILabel *storyLabel;//展示图
@end

@implementation DynamicStoryViewCell
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        [self configUI];
    }
    return self;
}
#pragma mark--UI布局部分

-(void)configUI {
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.equalTo(@150);
    }];
    
    [self.storyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImageView.left).offset(5);
        make.right.equalTo(self.backImageView.right);
        make.bottom.equalTo(self.backImageView.bottom);
    }];
}

-(UIImageView*)backImageView;
{
    if (_backImageView == nil) {
        _backImageView = [[UIImageView alloc]init];
        _backImageView.layer.cornerRadius = 4.0f;
        _backImageView.userInteractionEnabled = NO;
        _backImageView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:_backImageView];
    }
    return _backImageView;
}

- (UILabel *)storyLabel {
    if (_storyLabel == nil) {
        _storyLabel = [UILabel labelWithSystemFontSize:22 textColorHexString:@"#FFFFFF"];
        _storyLabel.font = [UIFont boldSystemFontOfSize:22];
        _storyLabel.numberOfLines = 0;
        _storyLabel.text = @"故事详情";
        [self.contentView addSubview:_storyLabel];
    }
    return _storyLabel;
}


@end


